import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './assets/aliyun/iconfont.css'
import ElementPlus from 'element-plus'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import 'element-plus/theme-chalk/index.css'
import i18n from '@/lang/i18n'
import indexedDBPlugin from '@/db/dbPlugin'
import './assets/css/edu.css'
import zhCN from 'element-plus/es/locale/lang/zh-cn'

let app = createApp(App)

// 注册图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
	app.component(key, component)
}
// 将关键词提取类注册为全局插件
app.directive('my-directive', {
	/* 自定义指令钩子 */
	mounted(el, bindings) {
		let title = router.currentRoute.value.meta.title
		if (el.dataset.title) {
			// 标题
			document.title = title + '-' + el.dataset.title
			// 关键词
			document.getElementsByName('keywords')[0].setAttribute('content', el.dataset.keywords)
			// 描述
			document.getElementsByName('description')[0].setAttribute('content', el.dataset.description)
		} else {
			document.title = '' + title
		}
	},

	updated(el, bindings) {
		let title = router.currentRoute.value.meta.title
		if (el.dataset.title) {
			// 标题
			document.title = title + '-' + el.dataset.title + '-DEXC区块开发者社区'
			// 关键词
			document.getElementsByName('keywords')[0].setAttribute('content', el.dataset.keywords)
			// 描述
			document.getElementsByName('description')[0].setAttribute('content', el.dataset.description)
		} else {
			document.title = '' + title + '-DEXC区块链开发者社区'
		}
	},
})

app
	.use(store as any)
	.use(router as any)
	.use(indexedDBPlugin as any)
	.use(ElementPlus, { locale: zhCN })
	.use(i18n)
	.mount('#app')
